<?php
/*
--- Accordion-Klasse ---
  Stellt ein Accordion dar, wie es
  bei Mootools zu finden ist.


  -- addItem($head, $text) --
     Fuegt dem Accordion ein neues
     Element mit der Ueberschrift $head
     und dem Text $text hinzu.

  -- getObject() --
     Gibt das aktuell verwendete
     (Javascript-)Objekt des Accordions
     zurueck.

  -- getActualAccordion() --
     Gibt die (Element-)ID des aktuellen
     Items zurueck

  -- getNextAccordion() --
     Gibt die (Element-)ID des naechsten
     Items zurueck

  -- HTMLOutput() --
     Schreibt Javascript-Informationen in
     die (globale) Variable $scripts und
     gibt den HTML-Code zurueck.
*/
$a1c2c3ordi4on5s = 0;
class Accordion
{
  var $account;
  var $elements;
  var $headline;
  var $content;

  function Accordion()
  {
    global $a1c2c3ordi4on5s;
    $a1c2c3ordi4on5s++;
    $this->account = $a1c2c3ordi4on5s;

    $this->elements = array();
    $this->headline = "h3.atStart";
    $this->content = "div.atStart";
  }

  function addItem($head, $text)
  {
    $this->elements[] = array($head, $text);
  }

  function getObject()
  {
    return "accordion".$this->account;
  }

  function getActualAccordion()
  {
    return count($this->elements)-1;
  }

  function getNextAccordion()
  {
    return $this->getActualAccordion()+1;
  }

  function HTMLOutput()
  {
    global $scripts;

    if(count($this->elements)>0) {
      $v = $this->account;
      $js = "var accordion".$v."; window.addEvent('domready', function(){accordion".$v." = new Accordion('".$this->headline."', '".$this->content."', {opacity: false,	onActive: function(toggler, element){toggler.setStyle('color', '#000077');},onBackground: function(toggler, element){toggler.setStyle('color', '#000077');}},$('accordion".$v."'));});";
      $html = "<div id=\"accordion".$v."\">\n";

      foreach($this->elements as $e) {
        $html .= "<h3 class=\"toggler atStart\">".$e[0]."</h3>";
        $html .= "<div class=\"element atStart\">".$e[1]."</div>";
      }

      $html .= "</div>\n";

      $scripts .= "<script type=\"text/javascript\">".$js."</script>\n";

      $this->Accordion();

      return $html;
    }
  }
}

?>